#include "Gomba.h"

Gomba::Gomba()
{
	_vx=0.01f;
	_vy=0.f;
}
Gomba::Gomba(float x, float y, float vx, float vy, int deltaTime,int resourceName,CResourceManager *rm):MovingObject(x,y,vx,vy,deltaTime,resourceName,rm)
{
	_isMovable = true;
}
Gomba::Gomba(float x, float y, int Width, int Height, float vx, float vy, int deltaTime, LPD3DXSPRITE spriteHandler, LPDIRECT3DTEXTURE9 image):MovingObject(x,y,Width,Height,vx,vy,deltaTime,spriteHandler,image)
{
	_isMovable = true;

}
Gomba::~Gomba(void)
{

}
void Gomba::SetXY(float _x,float _y)
{
	gX=_x;
	gY=_y;
}
void Gomba::Move()
{
	Vector v = _lastTranslateVector;
	float t1 = _lastTranslateVector.getY();
	float t2 = this->getVelocityVector().getY();
	float ty = t1 + t2;
	 
	if (this->getLastTranslateVector() != Vector() &&(ty<=0))
		{
			_vy = 0; 
		}
		else
			if (_vy < 1.5f)
   				_vy += 0.15f;

	if (_y >600 - 32) _vy =0;

	_lastX = _x;
	_lastY = _y;

	_x +=_vx*_deltaTime;
	_y +=_vy*_deltaTime;

	_lastTranslateVector = Vector();
}

void Gomba::setVelocity(Vector v)
{}

void Gomba::MoveLeft()
{
	_vx=-0.05f;
}
void Gomba::MoveRight()
{
	_vx=0.05f;
}
void Gomba::Render()
{
	float sx,sy;
	CScreen::getPosition(sx,sy);
	this->_sprite->Render(this->_x - sx,this->_y - sy);
}

void Gomba::actAfterCollided(int Direction)
{
	//if (_lastTranslateVector.getX() != 0 && _lastTranslateVector.getY() == 0)
	/*if (_lastTranslateVector.getX() != 0 && _lastTranslateVector.getY() == 0 && _vy != 0 && k == 1)
		_vx = -_vx;
	*/

	float k = abs(_lastX - _x);
	if (_canChangeVelocity)
	{
		if (k <= 0.5f)
		{
			_vx = -_vx;
			_canChangeVelocity = false;
		}
		else
			_canChangeVelocity = true;
	}
	else
		_canChangeVelocity = true;




	//switch(Direction)
	//{
	//case 1://UP
	//	{
	//		_vy = 0;
	//		break;
	//	}
	//case 2: //DOWN
	//	{
	//		break;
	//	}
	//case 3: //RIGHT
	//case 4: //LEFT
	//	{
	//		_vx = -_vx;
	//		//_vy = -_vy;
	//		break;
	//	}
	//case 0:
	//	break;
	//}
}